package cn.com.bod.fas.clm.controller;

import cn.com.bod.fas.clm.common.WordToPDF;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * @description 合同详情PDF获取
 * @author shihf
 * @date 2019年10月11日 15时44分08秒
 * @version 1.0.0
 * @Copyright (c) scfhdt
 */
@Controller
public class WordToPdfController {

	@GetMapping("/getContractPDF")
	public void getContractPdf(HttpServletResponse response) throws IOException {
		String filepath11 = "d:\\tmp\\11.docx";
		try(InputStream source = new FileInputStream(filepath11);) {
            response.setHeader("content-Type", "application/force-download");
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("金控.pdf", "utf-8"));
	        OutputStream target = response.getOutputStream();
	        
			Map<String, String> params = new HashMap<String, String>();
			params.put("perLimitLoanNo", "12345");
			params.put("signDate", "20190728");
			params.put("custName", "金控");
			params.put("idCard", "610321");
			WordToPDF.wordConverterToPdf(source,target,params);
			target.flush();
			target.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
